<template>
  <button
    class="panel-button"
    :class="[
      color,
      { 'has-sub': subLabel },
      { wrap: !wrap },
      { disabled: disabled },
    ]"
    @click="handleClick"
  >
    <span class="main-label" v-if="label">{{ label }}</span>
    <i v-if="icon" :class="['icon', icon]"></i>
    <span class="sub-label" v-if="subLabel">{{ subLabel }}</span>
    <i v-if="subIcon" :class="['sub-icon', subIcon]"></i>
  </button>
</template>

<script>
export default {
  name: "PanelButton",
  props: {
    buttonData: {
      type: Object,
      required: false,
    },
    label: {
      type: String,
      required: true,
    },
    icon: {
      type: String,
      default: "",
    },
    subLabel: {
      type: String,
      default: "",
    },
    subIcon: {
      type: String,
      default: "",
    },
    color: {
      type: String,
      default: "white",
      validator: (value) =>
        ["white", "yellow", "orange", "red"].includes(value),
    },
    wrap: {
      type: Boolean,
      default: true,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    handleClick() {
      if (!this.disabled) {
        this.$emit("click", {
          data: this.buttonData,
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.panel-button {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;

  // 主标签样式
  .main-label {
    font-size: 1.4em;
    line-height: 1;
    font-weight: 500;
    letter-spacing: 2px;
  }
  .icon {
    font-size: 1.8em;
  }

  // 副标签样式
  .sub-label {
    font-size: 0.7em;
    margin-top: 0.3em;
    color: #555;
    line-height: 1;
    margin-left: 1px;
  }
  .sub-icon {
    font-size: 0.8em;
    margin-top: 0.5em;
    color: #555;
    line-height: 1;
    margin-left: 1px;
  }

  // 立体效果 - 底部阴影
  &::before {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2%;
    background: linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.2),
      rgba(0, 0, 0, 0.4)
    );
    border-radius: 0 0 6px 6px;
    transition: all 0.2s ease;
  }

  // 有副标签时的样式
  &.has-sub {
    padding: 5% 0;
  }

  // 按下效果（仅对可点击按钮生效）
  &:not(.disabled):active {
    transform: scale(0.95);
    &::before {
      height: 5%;
    }
  }

  // 颜色方案
  &.white {
    background-color: #ffffff;
    color: #222;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8),
      0 2px 8px rgba(0, 0, 0, 0.4);
  }

  &.yellow {
    background-color: #ffeb3b;
    color: #222;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6),
      0 2px 8px rgba(0, 0, 0, 0.4);
  }

  &.orange {
    background-color: #ff9800;
    color: #222;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4),
      0 2px 8px rgba(0, 0, 0, 0.4);
  }

  &.red {
    background-color: #f44336;
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4),
      0 2px 8px rgba(0, 0, 0, 0.4);
  }

  // 文字换行控制
  &.wrap {
    white-space: normal;
    padding: 2px;
    line-height: 1.2;
  }

  &:not(.wrap) {
    white-space: nowrap;
  }

  // 禁用状态样式
  &.disabled {
    // opacity: 0.6;
    cursor: default !important;
    pointer-events: none;

    &::before {
      background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.1),
        rgba(0, 0, 0, 0.2)
      );
    }
  }

  // 可点击状态样式
  &:not(.disabled) {
    cursor: pointer;
  }
}

.asterisks-1-copy {
  font-size: 1.4em !important;
}
</style>